<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/bootstrap/img/favicon.ico">
<link href="${pageContext.request.contextPath }/bootstrap/css/style.min.css?v=4.0.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/animate.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/bootstrap/css/jquery-confirm.css"/>
<title>医院部门审核</title>
</head>
<body>
	<!-- 动态加载table -->
	<table id="depttab" class="table table-hover"></table>
	
	<div class="modal inmodal fade" id="myDeptModal" tabindex="-1" role="dialog"  aria-hidden="true">
    	<div class="modal-dialog modal-lg">
        	<div class="modal-content">
            	<div class="modal-header">
                	<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">部门审核</h4>
               	</div>
                <div class="modal-body">
                <input type="text" id="hospdeptid"/><input type="text" id="hospfatherdeptid"/><input type="text" id="hospfatherdeptid2"/>
                	<div class="form-group draggable">
						<label class="control-label">科室选择*</label>
						<select class="form-control" name="One_level_dept" id="One_level_dept" required="" aria-required="true" onchange="ChooseDept()">
							<option value="0">------请选择一级科室------</option>
						</select>
					</div>
                </div>
				<div class="modal-footer">
                	<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                	<button type="button" class="btn btn-primary" onclick="ExamineDeptSubmit()" id="SHBtn">提交</button>
           		</div>
           	</div>
        </div>
	</div>
	
	<script src="${pageContext.request.contextPath }/bootstrap/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/jquery-confirm.js"></script>
    <script>
    	$(function(){
    		DeptLoadding();
    	})
	  	//根据窗口调整表格高度
	    $(window).resize(function() {
	        $('#depttab').bootstrapTable('resetView', {
	            height: tableHeight()
	        })
	    })
	    //查询按钮事件
	    $('#search_btn').click(function(){
	        $('#depttab').bootstrapTable('refresh');
	    })
	    //tableHeight函数
	    function tableHeight(){
	        //可以根据自己页面情况进行调整
	        return $(window).height();
	    }
	  	function refreshTab(){
	  		$('#depttab').bootstrapTable('refresh');
	  	}
		//生成用户数据
	    $('#depttab').bootstrapTable({
	        method: 'get',
	        contentType: "application/x-www-form-urlencoded",//必须要有！！！！
	        url:"${pageContext.request.contextPath}/Main/HospDeptMan/HospDeptListAjax.action",//要请求数据的文件路径
	        height:tableHeight(),//高度调整
	        striped: true, //是否显示行间隔色
	        dataField: "rows",//bootstrap table 可以前端分页也可以后端分页，这里
	        //我们使用的是后端分页，后端分页时需返回含有total：总记录数,这个键值好像是固定的  
	        //rows： 记录集合 键值可以修改  dataField 自己定义成自己想要的就好
	        pageNumber: 1, //初始化加载第一页，默认第一页
	        pagination:true,//是否分页
	        queryParamsType:'limit',//查询参数组织方式
	        queryParams:function(params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的    
	            return {//这里的params是table提供的    
	                offset : params.offset,//从数据库第几条记录开始    
	                limit : params.limit,
	                check:2
	            //找多少条    
	            };},//请求服务器时所传的参数
	        sidePagination:'server',//指定服务器端分页
	        pageSize:10,//单页记录数
	        pageList:[1,5,10,30,50,100],//分页步进值
	        showRefresh:true,//刷新按钮
	        showColumns:true,
	        clickToSelect: true,//是否启用点击选中行
	        toolbarAlign:'right',//工具栏对齐方式
	        buttonsAlign:'right',//按钮对齐方式
	        toolbar:'#toolbar',//指定工作栏
	        columns:[
	            {
	                title:'全选',
	                field:'select',
	                //复选框
	                checkbox:true,
	                width:25,
	                align:'center',
	                valign:'middle'
	            },
	            {
	                title:'部门ID',
	                field:'hospdeptid'
	            },
	            {
	                title:'部门名称',
	                field:'hospdeptname'
	            },
	            {
	                title:'部门是否已审核',
	                field:'hospdeptischeck',
	                formatter:ischeck
	            },
	            {
	                title:'上级部门ID',
	                field:'hospdeptfatherid',
	                formatter:IDCheck
	            },
	            {
	                title:'上级部门名称',
	                field:'hospfatherdeptname',
	                formatter:ischeck
	            },
	            {
	                title:'上级部门是否已审核',
	                field:'hospfatherdeptnameischeck',
	                formatter:ischeck
	            },
	            {
	                title:'操作',
	                field:'operate',
	              	//列数据格式化
	                formatter:operate
	            },
	        ],
	        locale:'zh-CN',//中文支持,
	        responseHandler:function(rows){
	            //在ajax获取到数据，渲染表格之前，修改数据源
	            return rows;
	        }
	    })
	    //操作序列规则化
		function operate(value,row,index){
			if(row.hospdeptischeck=='false'){
				return '<button class="btn btn-primary" style="height:30px" onclick="Examine('+row.hospdeptid+','+row.hospdeptfatherid+')">审核</button>&nbsp&nbsp<button class="btn btn-primary" style="height:30px" onclick="Cancel('+row.hospdeptid+','+row.hospdeptfatherid+')">取消</button>';
			}
		}
		function ischeck(value,row,index){
			if(value=='false'){
				return '未审核';
			}else if(value=='true'){
				return '已审核';
			}else if(value=='null'){
				return '未填写';
			}else{
				return value;
			}
		}
		function IDCheck(value,row,index){
			if(value=='0'){
				return '无一级部门';
			}else if(value=='-1'){
				return '未选一级部门';
			}else{
				return value;
			}
		}
		function DeptLoadding(){
			$.ajax({  //页面首加载一级部门下拉框数据
	            type: "post",  
	            url: "${pageContext.request.contextPath}/Main/HospDeptMan/getHospitalDept.action",
	            contentType:"application/json;charset=utf-8",
	    		async: true,
	            success: function (data) {
	            	if(data.code=="100"){
	            		var datalist = data.list;
		                for (var i = 0; i < datalist.length; i++) {  
		                    $('#One_level_dept').append("<option value='" + datalist[i].hospdeptid + "' >" + datalist[i].hospdeptname + "</option>");  
		                } 
	            	}else{
	            		$.alert(data.msg);
	            	}
	            },  
	            error: function () {  
	                $.alert("加载一级部门失败!!!");  
	            }  
	        });
		}
		function ChooseDept(){
			var hospfatherdeptid = $('#One_level_dept').val();
			$("#hospfatherdeptid2").val(hospfatherdeptid);
		}
		function Examine(hospdeptid,hospfatherdeptid){
			$("#One_level_dept").val("0"); 
			$("#myDeptModal").modal('show');
			$("#hospfatherdeptid2").val("");
			$("#hospdeptid").val(hospdeptid);
			$("#hospfatherdeptid").val(hospfatherdeptid);
			//alert("hospdeptid="+hospdeptid+"&hospfatherdeptid="+hospfatherdeptid);
		}
		function ExamineDeptSubmit(){
			var hospdeptid=$("#hospdeptid").val();
			var One_level_dept = $('#One_level_dept').val();
			var hospfatherdeptid = $("#hospfatherdeptid").val();
			var hospfatherdeptid2 = $("#hospfatherdeptid2").val();
			if(hospfatherdeptid=='-1' && One_level_dept=='0'){
				$.alert("请指定一个一级部门！");
				return false;
			}else if(hospfatherdeptid=='-1' && One_level_dept!='0'){
				hospfatherdeptid=hospfatherdeptid2;
			}else if(hospfatherdeptid!='0' && hospfatherdeptid!='1' && One_level_dept!='0'){
				hospfatherdeptid=hospfatherdeptid2;
			}
			$.confirm({
			    title: '提示!',
			    content: '是否确认提交审核？',
			    type: 'blue',
			    typeAnimated: true,
			    buttons: {
			    	确定: function () {
			    		$("#SHBtn").html('<i class="fa fa-spinner fa-spin"></i>处理中...');
    		    		$("#SHBtn").prop('disabled',true);
			    		//向服务器发送医院确认订单操作！
			        	$.ajax({
			        		type:"post",
			        		url:"${pageContext.request.contextPath}/Main/HospDeptMan/ExamineDeptSubmit.action",
			        		async: true,
			                data:"hospdeptid="+hospdeptid+"&hospfatherdeptid="+hospfatherdeptid,
			               	success:function(data){
			               		$.alert(data.msg);
			               		if(data.code==100){
			               			$('#myDeptModal').modal('hide');
			               			refreshTab();
			               		}
			               		$("#SHBtn").html('提交');
		    		    		$("#SHBtn").prop('disabled',false);
			               	},error:function(request){
			               		alert("请求出错了！");
			               		$("#SHBtn").html('提交');
		    		    		$("#SHBtn").prop('disabled',false);
			               	}
			        	})
			    	},
					取消: function () {$('#myDeptModal').modal('hide');},
			    }	
			});
		}
		function Cancel(hospdeptid,hospfatherdeptid){
			//alert(hospdeptid+":"+hospfatherdeptid);
		}
	</script>
</body>
</html>